﻿namespace Core
{
    [NumericWatcher(NumericType.Hp)]
    public class NumericWatcher_Hp : INumericWatcher
    {
        void INumericWatcher.Run(NumbericChange args)
        {
            var numericComponent = args.Unit.GetComponent<NumericComponent>();
            var hpMax = numericComponent[NumericType.HpMax];
            if(args.New >  hpMax)
            {
                numericComponent[args.NumericType] = hpMax;
                return;
            }

            //Log.Debug($"{args.Unit.transform} {args.New}");

            if(args.New <= 0)
            {
                args.Unit.SurvivalState = UnitSurvivalState.Death;
                args.Unit?.GetComponent<CollideComponent>()?.SetEnable(false);
            }
        }
    }
}